package com.sy.controller.saleController;

import com.sy.bean.finance.FinanceBill;
import com.sy.bean.sale.ErpSale;
import com.sy.bean.sale.params.AddSale;
import com.sy.bean.sale.params.SaleQuery;
import com.sy.bean.sale.params.UpStatus;
import com.sy.common.bean.PageBean;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.common.utils.BeanOfMap;
import com.sy.controller.finance.FinanceBillController;
import com.sy.service.finance.FinanceBillService;
import com.sy.service.saleService.SaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/sale")
@Api(tags = "销售单")
public class SaleController extends BaseController {
    @Autowired
    SaleService saleService;
    @Autowired
    FinanceBillController financeBillController;

    @PostMapping("/query")
    @ApiOperation("销售退货单列表")
    public ResultBean<ErpSale> query(@RequestBody SaleQuery query) {
        return success("查询成功", saleService.query(BeanOfMap.bom(query)));
    }

    @PostMapping("/save")
    @ApiOperation("新增销售退货单")
    public ResultBean save(@RequestBody AddSale addSale) {
        return saleService.save(addSale) > 0 ? success("保存成功") : fail("保存失败");
    }

    @PostMapping("/upStatus")
    @ApiOperation("审核销售退货单")
    public ResultBean upStatus(@RequestBody UpStatus upStatus) {
        int rs = saleService.upStatus(upStatus);
        return rs==1?success("审核成功"):fail("审核失败");
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除销售退货单")
    public ResultBean upStatus(int id) {
        return saleService.delete(id) > 0 ? success("删除成功") : fail("删除失败");
    }
}
